#define DEBUG
#include <cstdio>
#include <cmath>

using namespace std;

const int maxsize=300000, maxn=7, inf=0x7ffffff;

int min(int a, int b) {
  return a<b ? a : b;
}

int solve(int o, int n, int s[]) {
  int ret=inf;
  if (o<n) {
    for (int i=1; i<=n; i++) {
      if (s[i]>=0) {
	for (int j=i+1; j<=n; j++) {
	  if (s[j]>=0) {
	    int x=s[i], y=s[j];
	    s[j] = -1;
	    s[i] = x+y;
	    if (s[i]==0) {
	      return 0;
	    }
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = x*y;
	    if (s[i]==0) {
	      return 0;
	    }
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = abs(x-y);
	    if (s[i]==0) {
	      return 0;
	    }
	    ret = min(solve(o+1, n, s), ret);
	    if (!ret) {
	      return 0;
	    }
	    s[i] = x, s[j]=y;
	  }
	}
      }
    }
  } else {
    for (int i=1; i<=n; i++) {
      if (s[i]>=0) {
	ret = s[i];
	break;
      }
    }
  }
  return ret;
}

int main() {
  freopen("game.in", "r", stdin);
  freopen("game.out", "w", stdout);

  int t;
  scanf("%d", &t);
  for (int ti=1; ti<=t; ti++) {
    static int s[maxsize+1];
    int n;
    scanf("%d", &n);
    bool flag=false;
    for (int i=1; i<=n; i++) {
      scanf("%d", s+i);
      if (s[i]==0) {
	flag = true;
      }
    }
    if (n>maxn && flag) {
      printf("0\n");
      continue;
    }
    printf("%d\n", solve(1, n, s));
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
